<?php

/**
 * @author Argel Cabalag
 * @copyright 2009
 */

class mainActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
  	$this->form = new HomeForm();
  	      
    $q = Doctrine_Query::create()
    ->from('Client c')
    ->orderBy('c.created_at DESC')
    ->limit('10');
    $this->client_list = $q->execute();

    $p = Doctrine_Query::create()
    ->from('Person p')
		->where('p.type = ?', 'PX')
    ->orderBy('p.created_at DESC')
    ->limit('10');
    $this->px_list = $p->execute();

  }
 public function executeSearch(sfWebRequest $request)
  {
	  $this->form = new SearchForm();
	  
	  $s = $this->getRequestParameter('list');
	  $this->s = $s;
	  $query = '%'.$this->getRequestParameter('query').'%';

	  if($s == 'MC')
	  {
		  $m = Doctrine_Query::create()
		  ->from('Client c')
		  ->where('c.name LIKE ?', $query);
		  $this->list = $m->execute();
	  }
	  elseif($s == 'PX')
	  {
	  	
		  $mm = Doctrine_Query::create()
		      ->select('px.*, p.*')
              ->from('Passenger px, px.Person p')
              ->where('p.last_name LIKE ?', $query)
              ->orWhere('p.first_name LIKE ?', $query);
                

		  $this->list2 = $mm->execute();			
	  }	  
	}
	
	public function executeAdd(sfWebRequest $request)
	  {
		
		  
		  	  
		}
	
	
}

?>